<?php


namespace app\index\controller;


use think\Controller;
use app\index\model\Task as ModelTask;
use think\Db;
use think\Session;

class Task extends Controller
{
    public function onloadTask(){
       if($this->request->isAjax()){
           $jsonData = $this->request->param("datas");
           $jsonData = json_encode($jsonData);
           $data = ['task_member_name'=>\think\facade\Session::get("login"),'task_list'=>$jsonData];
           $task = new ModelTask();
           if(!\think\facade\Session::has("login")){
               //账户没有登录
               return 0;
           }
           if($task->where("task_member_name",\think\facade\Session::get("login"))->find()==null){
               $task->insertGetId($data,true);
               // 数据已更新
               return 1;
           }else{
               $task->where("task_member_name",\think\facade\Session::get("login"))->update(['task_list'=>$jsonData]);
               // 数据已更新
               return 1;
           }
       }else{
//           return "不是一个ajax请求";
           return 2;
       }
    }

    public function loadTask(){
        if($this->request->isAjax()){
            $task = new ModelTask();
            if(\think\facade\Session::has("login")){
                $datas = $task->where("task_member_name",\think\facade\Session::get("login"))->find();
                return $datas->task_list;
            }
            else{
                return null;
            }
        }else{
            return null;
        }
    }
}